/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufrn.dca.interfaceGrafica;

import br.ufrn.dca.controle.tipoPID;
import br.ufrn.dca.identificacao.tipoSistema;

/**
 *
 * @author allan
 */
public class JanelaConfig extends javax.swing.JDialog {

    /**
     * Referência para a janela principal
     */
    JanelaPrincipal jp;

    /*
     * Creates new form JanelaConfig
     */
    public JanelaConfig(java.awt.Frame parent, boolean modal, JanelaPrincipal jp) {
        super(parent, modal);
        initComponents();
        this.jp = jp;
        setSize(280, 400);
        setLocationRelativeTo(jp);
        FOPDTRadioButton.setSelected(true);
        this.ZNRadioButton.setSelected(true);
        this.CCRadioButton.setVisible(true);
        this.ZNRadioButton.setVisible(true);

        this.LR2RadioButton.setVisible(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ModeloIdentbuttonGroup = new javax.swing.ButtonGroup();
        PIDbuttonGroup = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        PortaText = new javax.swing.JTextField();
        HostText = new javax.swing.JTextField();
        CancelarButton = new javax.swing.JButton();
        ConfigButton = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        FOPDTRadioButton = new javax.swing.JRadioButton();
        SOPDTRadioButton = new javax.swing.JRadioButton();
        jPanel3 = new javax.swing.JPanel();
        ZNRadioButton = new javax.swing.JRadioButton();
        CCRadioButton = new javax.swing.JRadioButton();
        LR2RadioButton = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Configurações");
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Conexão", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial Unicode MS", 1, 12))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        jLabel1.setText("Host:");

        jLabel2.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        jLabel2.setText("Porta:");

        PortaText.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        PortaText.setText("20081");

        HostText.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        HostText.setText("10.13.99.69");
        HostText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HostTextActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addGap(27, 27, 27)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(HostText, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE)
                    .addComponent(PortaText))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(HostText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(PortaText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        CancelarButton.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        CancelarButton.setText("Cancelar");
        CancelarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelarButtonActionPerformed(evt);
            }
        });

        ConfigButton.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        ConfigButton.setText("Ok");
        ConfigButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ConfigButtonActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Modelo Identificado", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial Unicode MS", 1, 12))); // NOI18N

        ModeloIdentbuttonGroup.add(FOPDTRadioButton);
        FOPDTRadioButton.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        FOPDTRadioButton.setText("FOPDT");
        FOPDTRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FOPDTRadioButtonActionPerformed(evt);
            }
        });

        ModeloIdentbuttonGroup.add(SOPDTRadioButton);
        SOPDTRadioButton.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        SOPDTRadioButton.setText("SOPDT");
        SOPDTRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SOPDTRadioButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(FOPDTRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
                .addComponent(SOPDTRadioButton)
                .addGap(43, 43, 43))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(FOPDTRadioButton)
                    .addComponent(SOPDTRadioButton))
                .addGap(79, 79, 79))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Controlador", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial Unicode MS", 1, 12))); // NOI18N

        PIDbuttonGroup.add(ZNRadioButton);
        ZNRadioButton.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        ZNRadioButton.setText("Ziegler-Nichols");

        PIDbuttonGroup.add(CCRadioButton);
        CCRadioButton.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        CCRadioButton.setText("Cohen-Coon");
        CCRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CCRadioButtonActionPerformed(evt);
            }
        });

        PIDbuttonGroup.add(LR2RadioButton);
        LR2RadioButton.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        LR2RadioButton.setText("L.R. 2ª Ordem");
        LR2RadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LR2RadioButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(LR2RadioButton)
                    .addComponent(CCRadioButton)
                    .addComponent(ZNRadioButton))
                .addContainerGap(114, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(ZNRadioButton)
                .addGap(3, 3, 3)
                .addComponent(CCRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(LR2RadioButton)
                .addGap(28, 28, 28))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(ConfigButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CancelarButton)
                        .addGap(23, 23, 23))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ConfigButton)
                    .addComponent(CancelarButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void CancelarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelarButtonActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_CancelarButtonActionPerformed

    private void ConfigButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ConfigButtonActionPerformed
        // TODO add your handling code here:
        String host = HostText.getText();
        int porta = Integer.parseInt(PortaText.getText());
        jp.getFluxo().setHost(host);
        jp.getFluxo().setPorta(porta);
        jp.getFluxo().setConfigurado(true);

        if (FOPDTRadioButton.isSelected()) {
            jp.getRele().getNopdt().setTipo(tipoSistema.FOPDT);
            if (ZNRadioButton.isSelected()) {
                jp.getPid().setTipo(tipoPID.ZN);
            }
            if (CCRadioButton.isSelected()) {
                jp.getPid().setTipo(tipoPID.COHENCOON);
            }
        } else {
            jp.getRele().getNopdt().setTipo(tipoSistema.SOPDT);
            jp.getPid().setTipo(tipoPID.LR_2ORDEM);
        }

        this.dispose();
    }//GEN-LAST:event_ConfigButtonActionPerformed

    private void HostTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HostTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_HostTextActionPerformed

    private void CCRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CCRadioButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_CCRadioButtonActionPerformed

    private void LR2RadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LR2RadioButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_LR2RadioButtonActionPerformed

    private void SOPDTRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SOPDTRadioButtonActionPerformed
        // TODO add your handling code here:
        this.CCRadioButton.setVisible(false);
        this.ZNRadioButton.setVisible(false);

        this.LR2RadioButton.setVisible(true);
        this.LR2RadioButton.setSelected(true);
        setSize(280, 400);
    }//GEN-LAST:event_SOPDTRadioButtonActionPerformed

    private void FOPDTRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FOPDTRadioButtonActionPerformed
        // TODO add your handling code here:
        this.CCRadioButton.setVisible(true);
        this.ZNRadioButton.setVisible(true);
        this.ZNRadioButton.setSelected(true);

        this.LR2RadioButton.setVisible(false);
        setSize(280, 400);
    }//GEN-LAST:event_FOPDTRadioButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton CCRadioButton;
    private javax.swing.JButton CancelarButton;
    private javax.swing.JButton ConfigButton;
    private javax.swing.JRadioButton FOPDTRadioButton;
    private javax.swing.JTextField HostText;
    private javax.swing.JRadioButton LR2RadioButton;
    private javax.swing.ButtonGroup ModeloIdentbuttonGroup;
    private javax.swing.ButtonGroup PIDbuttonGroup;
    private javax.swing.JTextField PortaText;
    private javax.swing.JRadioButton SOPDTRadioButton;
    private javax.swing.JRadioButton ZNRadioButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    // End of variables declaration//GEN-END:variables
}
